<template>
  <CmArticle @addAgree="addAgree" :res="res" :noData="noData">
    <div class="no-data fx-c" v-if="!noData" style="padding: 4rem 2rem">
      {{ word }}
    </div>
  </CmArticle>
</template>

<script>
import CmArticle from "@/components/common/CmArticle";
import { normlizeArticleMsg, parse, getSessionStorage } from "@/utils/utils";
import { getUserArticles } from "@/api/article";
export default {
  name: "UserArticle",
  components: {
    CmArticle,
  },
  data() {
    return {
      res: [],
      noData: true,
      word: "作者还没有发布文章哦",
    };
  },
  async created() {
    const i = getSessionStorage("cid");
    let id;
    if (i) {
      id = parse(i).id;
    }
    const res = await getUserArticles(id);
    this.res = normlizeArticleMsg(res.data);
    if (!this.res.length) this.noData = false;
  },
  methods: {
    addAgree(obj) {
      this.res[obj.key].agree += obj.num;
    },
  },
};
</script>